from Platforms.restapifactory import RestAPIFactory
from Strategy.config import CONFIG, STATIC

class Account:
    def __init__(self, platform, type):
        self.type = type
        
        factory = RestAPIFactory()
        self.platform = factory.get_platform(platform)

        if type == 'trade' or type == 'margin':
            self.balance = self.platform.get_balances(type)
        elif type == 'pl':  #assume all margin trading are based in USDT
            self.balance = dict()
            self.balance['USDT'] = 0
            position = self.platform.get_positions()
            for symbol in position:
                self.balance['USDT'] += float(position[symbol])
        elif type == 'cash':
            self.balance = STATIC.account_cash

    def get_balances(self):
        return self.balance

    def get_currency(self, currency):
        return self.platform.get_currency(currency)
